using UnityEngine;

public class ResultUISur : MonoBehaviour
{
	private GameObject pauseobj;

	public UIEventListener mainbtn;

	public UILabel wavelabel;

	public UILabel bestlabel;

	public UISlider expslider;

	public UISprite currankflag;

	public UISprite nextrankflag;

	public UILabel exp_label;

	private float curexp;

	private float rateexp;

	private int endexp;

	private bool exprunflag;

	public SurData cursurdata;

	public UILabel explabel;

	public UILabel moneylabel;

	public GameObject[] rewardobj;

	public GameObject diamondobj;

	public UILabel diamondlabel;

	public GameObject pieceobj;

	public Piece_item pieceitem;

	public UIWidget colliderwi;

	private int finishwave;

	private bool poprankui;

	private int firstlevel;

	private bool temp_first;

	private void Start()
	{
		mainbtn.onClick = OnClickmainBtn;
	}

	private void Update()
	{
		if (exprunflag)
		{
			if (curexp < (float)endexp)
			{
				curexp += Time.deltaTime * rateexp;
			}
			else
			{
				curexp = endexp;
				exprunflag = false;
			}
			expshow((int)curexp);
		}
	}

	public void initinfo()
	{
		if (TasksController.instance.curwave < 0)
		{
			finishwave = 0;
		}
		else
		{
			finishwave = TasksController.instance.curwave;
		}
		wavelabel.text = string.Empty + (TasksController.instance.curwave + 1);
		bestlabel.text = string.Empty + GamePlayerprefs.instance.readsurbestwave(GlobalInf.chanllenge_mode);
		if (finishwave > 3)
		{
			MonoInstance<AudioController>.instance.play(AudioType.UI_gameover_suc, 0f);
		}
		rewardShow();
		saveAchi();
	}

	public void saveAchi()
	{
		GamePlayerprefs.instance.readachievement();
		GamePlayerprefs.instance.readdailytask();
		GamePlayerprefs.instance.savefightinfo();
		GamePlayerprefs.instance.additemachi(10, 1);
		switch (GlobalInf.chanllenge_mode)
		{
			case 0:
				GamePlayerprefs.instance.saveitemachi(11, TasksController.instance.curwave + 1);
				break;
			case 1:
				GamePlayerprefs.instance.saveitemachi(12, TasksController.instance.curwave + 1);
				break;
			case 2:
				GamePlayerprefs.instance.saveitemachi(13, TasksController.instance.curwave + 1);
				break;
		}
		GamePlayerprefs.instance.savedailytask(2);
	}

	public void rewardShow()
	{
		cursurdata = DataController.instance.surdata[GlobalInf.chanllenge_mode];
		float num = 300f - TasksController.instance.survivalchanllenge.TimeCal;
		if (num < 60f)
		{
			Platform.flurryEvent_challenge(1, GlobalInf.chanllenge_mode, 1);
		}
		else if (num < 180f)
		{
			Platform.flurryEvent_challenge(1, GlobalInf.chanllenge_mode, 2);
		}
		else
		{
			Platform.flurryEvent_challenge(1, GlobalInf.chanllenge_mode, 3);
		}
		curexp = GamePlayerprefs.instance.allexp;
		endexp = (int)curexp + cursurdata.explist[finishwave];
		rateexp = (float)cursurdata.explist[finishwave] / 2f;
		expshow((int)curexp);
		exprunflag = true;
		if (cursurdata.gemlist[finishwave] <= 0)
		{
			cursurdata.gemlist[finishwave] = 1;
		}
		explabel.text = string.Empty + cursurdata.explist[finishwave];
		moneylabel.text = string.Empty + cursurdata.moneylist[finishwave];
		diamondlabel.text = string.Empty + cursurdata.gemlist[finishwave];
		if (cursurdata.piecelist[finishwave] != -1)
		{
			if (UnityEngine.Random.Range(1, 101) <= cursurdata.gailvlist[finishwave])
			{
				GamePlayerprefs.instance.readpiece();
				PieceData pieceData = DataController.instance.Getpiece(cursurdata.piecelist[finishwave]);
				pieceitem.enable(pieceData);
				GamePlayerprefs.instance.addpiece(pieceData.id, 1);
			}
			else
			{
				NGUITools.SetActive(pieceobj, state: false);
			}
		}
		else
		{
			NGUITools.SetActive(pieceobj, state: false);
		}
		GamePlayerprefs.instance.add_exp(cursurdata.explist[finishwave]);
		GamePlayerprefs.instance.add_money(cursurdata.moneylist[finishwave]);
		GamePlayerprefs.instance.add_diamond(cursurdata.gemlist[finishwave]);
		GamePlayerprefs.instance.setsurbestwave(GlobalInf.chanllenge_mode, TasksController.instance.curwave + 1);
		Platform.flurryEvent_sur(TasksController.instance.curwave + 1);
	}

	public void expshow(int expnum)
	{
		expdata exp = GamePlayerprefs.instance.GetExp(expnum);
		if (exp.level >= 19)
		{
			expslider.value = 1f;
			exp_label.text = string.Empty;
			currankflag.spriteName = "19." + GamePlayerprefs.instance.ranknameImage[exp.level - 1];
			nextrankflag.enabled = false;
			currankflag.SetDimensions(56, 48);
			nextrankflag.SetDimensions(56, 48);
		}
		else
		{
			expslider.value = (float)exp.curexp / (float)exp.maxexp;
			exp_label.text = string.Empty + exp.curexp + "/" + exp.maxexp;
			currankflag.spriteName = string.Empty + exp.level + "." + GamePlayerprefs.instance.ranknameImage[exp.level - 1];
			nextrankflag.spriteName = string.Empty + (exp.level + 1) + "." + GamePlayerprefs.instance.ranknameImage[exp.level];
			if (exp.level >= 15)
			{
				currankflag.SetDimensions(56, 48);
				nextrankflag.SetDimensions(56, 48);
			}
			else if (exp.level < 14)
			{
				currankflag.SetDimensions(40, 44);
				nextrankflag.SetDimensions(40, 44);
			}
			if (exp.level == 14)
			{
				currankflag.SetDimensions(40, 44);
				nextrankflag.SetDimensions(56, 48);
			}
		}
		showrankeui(exp.level);
	}

	public void showrankeui(int level)
	{
		if (!poprankui)
		{
			if (!temp_first)
			{
				firstlevel = level;
				temp_first = true;
			}
			if (level == firstlevel + 1)
			{
				GameUIController.instance.enable_rankui();
				poprankui = true;
			}
		}
	}

	public void OnClickmainBtn(GameObject btn)
	{
		Platform.HideFeatureView();
		MenuUIController.beginshow = BeginShow.main;
		Time.timeScale = 1f;
		UnityEngine.SceneManagement.SceneManager.LoadScene("Menu");
		MidLoading.loadlevel = 0;
	}

	public void enable()
	{
		if (pauseobj == null)
		{
			pauseobj = base.gameObject;
		}
		NGUITools.SetActive(pauseobj, state: true);
		initinfo();
		colliderwi.alpha = 1f; colliderwi.gameObject.SetActive(true);
		Invoke("showad", 0.5f);
	}

	public void showad()
	{
		colliderwi.alpha = 0f; colliderwi.gameObject.SetActive(false);
		Platform.ShowFeatureView();
		Platform.ShowFullScreenSmall();
	}

	public void disable()
	{
		NGUITools.SetActive(pauseobj, state: false);
	}
}
